package com.gzwl.controller.fileupload;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/pic")
public class FileUploadController {

	@RequestMapping("/picUpload")
	@ResponseBody
	public String WebFileUpload(HttpServletRequest request, MultipartFile multipartFile) {
		if (null != multipartFile) {
			String OriginalFilename = multipartFile.getOriginalFilename();
			try {
				multipartFile.transferTo(new File("D:/share/"+UUID.randomUUID()+OriginalFilename.substring(OriginalFilename.lastIndexOf("."))));
				System.out.println(multipartFile.getOriginalFilename());
				return "success";
			} catch (Exception e) {
				e.printStackTrace();
				return "error";
			} 
		}
		return "error";
	}
}
